package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ykeezy
 * @version 1.0
 * @date 2024/9/3 23:33
 * @description TODO
 */
@Api(tags = "护理计划")
@AllArgsConstructor
@RestController
@Slf4j
@RequestMapping("/nursing/plan")
public class NursingPlanController extends BaseController{
    private NursingPlanService nursingPlanService;

    @ApiOperation(value = "根据Id进行更新")
    @PutMapping("/{id}")
    public ResponseResult updateById(@PathVariable Long id, @RequestBody NursingPlanDto nursingPlanDto){
        return nursingPlanService.updateById(nursingPlanDto, id);

    }

    @ApiOperation(value = "根据Id删除")
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable Long id){
        return nursingPlanService.deleteById(id);

    }

    @ApiOperation(value = "启用或禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult enableOrDisable(@PathVariable Long id, @PathVariable Integer status){
        System.out.println(id + " -- " +status);
        return nursingPlanService.enableOrDisable(id, status);

    }

    @GetMapping
    @ApiOperation(value = "获取所有护理计划", notes = "无参数，获取所有护理计划，返回护理计划列表")
    public ResponseResult<List<NursingPlanVo>> getAllPlans() {
        return success(nursingPlanService.getAllPlans());
    }

    @PostMapping
    @ApiOperation(value = "新增护理计划", notes = "传入护理计划信息，返回添加结果")
    public ResponseResult addPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.addPlan(nursingPlanDto);
        return success();
    }

    @GetMapping("/search")
    @ApiOperation(value = "条件分页查询护理计划")
    public ResponseResult<PageResponse<NursingPlanVo>> search(
            @ApiParam(value = "name", required = false) String name,
            @ApiParam(value = "status", defaultValue = "1") Integer status,
            @ApiParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        return success(nursingPlanService.search(name, status, pageNum, pageSize));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理计划")
    public ResponseResult<NursingPlanVo> getPlanById(@PathVariable Long id) {
        return success(nursingPlanService.getPlanById(id));
    }

}
